/**
 * 
 */
package info.niwota.calculator;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;

/**
 * @author qiangli
 * 
 */
public class RestrictedActivity extends Calculator {
	public static final String ACTION_POWERUP_QUIT = "info.niwota.intent.ACTION_POWERUP_QUIT";

	private static final String TAG = "RestrictedActivity";

	@Override
	public void onCreate(Bundle instanceState) {
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

		super.onCreate(instanceState);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (Debug.DEBUG) {
			Log.d(TAG, "onKeyDown" + keyCode);
		}
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (mPanelSwitcher.getCurrentIndex() == ADVANCED_PANEL) {
				mPanelSwitcher.moveRight();
			} else {
				doQuit();
			}
			return true;
		}
		
		if (keyCode == KeyEvent.KEYCODE_MENU) {
			return false;
		}

		return true;
	}

	private void doQuit() {
		Intent i = new Intent(ACTION_POWERUP_QUIT);
		sendOrderedBroadcast(i, null);
		//
		finish();
	}
}
